/*********************
* Author:Dzlua
* QQ:505544956
* time:2016/08/11
*/
#ifndef __EDUI_STRING_H__
#define __EDUI_STRING_H__

#include "RefBase.h"
#include <stdarg.h>

EDUI_NAMESPACE_BEGIN

class EDUI_API String : public RefCountedBase
{
public:
    enum { MAX_LOCAL_STRING_LEN = 63 };
    String();
    String(const char ch);
    String(const String& src);
    String(const char* str, int nLen = -1);
    ~String();

    void Empty();
    int GetLength() const;
    bool IsEmpty() const;
    char GetAt(int nIndex) const;
    void Append(const char* pstr);
    void Assign(const char* pstr, int nLength = -1);
    void Resize(int length);
    const char* GetString() const;
    char* GetData();

    void SetAt(int nIndex, char ch);
    operator const char*() const;

    char operator[] (int nIndex) const;
    const String& operator=(const String& src);
    const String& operator=(const char ch);
    const String& operator=(const char* pstr);


    String operator+(const String& src) const;
    String operator+(const char* pstr) const;
    const String& operator+=(const String& src);
    const String& operator+=(const char* pstr);
    const String& operator+=(const char ch);

    bool operator == (const char* str) const;
    bool operator != (const char* str) const;
    bool operator <= (const char* str) const;
    bool operator <  (const char* str) const;
    bool operator >= (const char* str) const;
    bool operator >  (const char* str) const;

    int Compare(const char* pstr) const;
    int CompareNoCase(const char* pstr) const;

    void MakeUpper();
    void MakeLower();

    String Left(int nLength) const;
    String Mid(int iPos, int nLength = -1) const;
    String Right(int nLength) const;

    int Find(char ch, int iPos = 0) const;
    int Find(const char* pstr, int iPos = 0) const;
    int ReverseFind(char ch) const;
    int Replace(const char* pstrFrom, const char* pstrTo);
    void Replace(const char* pstrTo, int pos,int len=0);
    bool Remove(int pos,int len=1);
    int Format(const char* pstrFormat, ...);
    int Format(const char* pstrFormat, va_list Args);
    int SmallFormat(const char* pstrFormat, ...);

protected:
    char* m_pstr;
    char m_szBuffer[MAX_LOCAL_STRING_LEN + 1];
REF_IMPLEMENT_COUNTING(String);
};

EDUI_NAMESPACE_END

#endif